
/*------------------------------------------------------------------------------

	SECTION B. Table B.1 Descriptive statistics 

------------------------------------------------------------------------------*/

qui reghdfe hunger pkoarmed  $micro $macro, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
sum $outcome $mediators $micro agri_ih2010 pasture_ih2010 pkoarmed pkoUNMIS if e(sample)==1


/*------------------------------------------------------------------------------

	SECTION C. Selection bias 

------------------------------------------------------------------------------*/

*	SECTION C.1 - Parallel trends in violence

preserve
	use "Replication_conflict_cty_year.dta",clear
	collapse (sum) ucdp_count acled_ deaths_civilians, by(pkoever year)
	cap drop y1 x1 y2 x2 y1_1 x1_1 y2_1 x2_1
	gen y1= 38
	gen x1= 2012.5
	gen y2= 37
	gen x2= 2011.2
	gen y1_1= 38
	gen x1_1= 2003
	gen y2_1= 37
	gen x2_1= 2004.9
	two line ucdp_count year if pkoever==1 & year<2018 & year>1995, sort lcolor(black) lpattern(solid)  || /*
	*/ pcarrow y1 x1 y2 x2, lcolor(black) mlcolor(black)||/*
	*/ pcarrow y1_1 x1_1 y2_1 x2_1, lcolor(black) mlcolor(black)||/*
	*/ line ucdp_count year if pkoever==0 & year<2018 & year>1995 , sort lcolor(black) lpattern(dash) scheme(plotplain) /*
	*/ ytitle("Violent events (UCDP)") xtitle("Year") yscale(range(0 50)) ylabel(0(10)50) xscale(range(1996 2017)) xlabel(1996(2)2017) legend(order(1 "PK deployment" 4 "No Deployment") /*
	*/ cols(1) ring(0) bplacement(nw) region(lstyle(none))) xline(2011, lpattern(solid)) xline(2005, lpattern(solid)) text(38 2014 "UNMISS") text(38 2002 "UNMIS")
	graph export "~/Events_parallel_96-17UCDP.pdf", replace
	
	cap drop y1 x1 y2 x2 y1_1 x1_1 y2_1 x2_1
	gen y1= 350
	gen x1= 2012.5
	gen y2= 345
	gen x2= 2011.2
	gen y1_1= 300
	gen x1_1= 2003.2
	gen y2_1= 295
	gen x2_1= 2004.9
	two line acled_ year if pkoever==1 & year<2018 & year>1995, sort lcolor(black) lpattern(solid)  || /*
	*/ pcarrow y1 x1 y2 x2, lcolor(black) mlcolor(black)||/*
	*/ pcarrow y1_1 x1_1 y2_1 x2_1, lcolor(black) mlcolor(black)||/*
	*/ line acled_ year if pkoever==0 & year<2018 & year>1995, sort lcolor(black) lpattern(dash) scheme(plotplain) /*
	*/ ytitle("Violent events (ACLED)") xtitle("Year") xscale(range(1996 2017)) xlabel(1996(2)2017) legend(order(1 "PK deployment" 4 "No Deployment") /*
	*/ cols(1) ring(0) bplacement(nw) region(lstyle(none))) xline(2011, lpattern(solid)) xline(2005, lpattern(solid)) text(360 2014 "UNMISS") text(310 2002 "UNMIS")
	graph export "~/Events_parallel_96-17Acled.pdf", replace
restore

*	SECTION C.2 - Past violence as determinants of peacekeeping deployment

preserve
	use "Replication_acled.dta",clear
	xtreg pkoarmed f(1/4).acled l(0/5).acled, fe cluster(cty)
	
	test L1.acled + L2.acled + L3.acled + L4.acled + L5.acled =0
	*p-value 0.397
restore


*	SECTION C.3 - County-level Determinant of Peacekeeping Deployment

preserve
	use "Replication_detpko.dta",clear

	*  rescale for better visualization  
	foreach var of varlist ttime_mean agri_ih capdist pasture_ih prec_gpcp  {
		replace `var'=`var'/100
		}
	replace pop_gpw_sum=pop_gpw_sum/1000
		
	* one covariate at the time
	foreach var of varlist ttime_mean capdist agri_ih pasture_ih nlights_mean  pop_gpw_sum urban_ih prec_gpcp  pkoUNMIS {
		reg pkoever `var', vce(r)
		}
	* all covariates
	reg pkoever ttime_mean capdist agri_ih  nlights_mean pasture_ih pop_gpw_sum prec_gpcp urban_ih pkoUNMIS, vce(r)
restore


*	SECTION C.4 - Matching Households
 

*  Propensity score matching

foreach outcome of global outcome {

	teffects psmatch (`outcome') /*
	*/(pkoarmed  $micro $macro i.state i.wave_number), /*
	*/ atet vce(r)

	* check balance
	tebalance summarize 
	}


foreach outcome of global outcome {
	teffects ipwra (`outcome' $micro $macro i.state i.wave_number) /*
	*/(pkoarmed  $micro $macro i.state i.wave_number), /*
	*/ atet vce(r)
		
	* check balance
	tebalance summarize 
	}
	

* SECTION C.5	- Instrumenting Peacekeeping 
	
* install ado "ivreg2" 

ssc install ivreg2, replace
ssc install ranktest, replace

* create interactions of county-level control with wave dummies
gen agri_w1=agri_ih2010*1.wave_number
gen agri_w2=agri_ih2010*2.wave_number
gen agri_w3=agri_ih2010*3.wave_number
gen pasture_w1=pasture_ih*1.wave_number
gen pasture_w2=pasture_ih*2.wave_number
gen pasture_w3=pasture_ih*3.wave_number


xi: ivreg2 pcqcons $micro i.wave_number agri_w* pasture_w* /*
		*/ (pkoarmed=pkoUNMIS) , cluster(idhh)
xi: ivreg2  hunger $micro i.wave_number agri_w* pasture_w* /*
		*/ (pkoarmed=pkoUNMIS) , cluster(idhh)
xi: ivreg2 pcqpurc $micro i.wave_number agri_w* pasture_w* /*
		*/ (pkoarmed=pkoUNMIS)  , cluster(idhh)
xi: ivreg2 pcwealthdg $micro i.wave_number agri_w* pasture_w* /*
		*/ (pkoarmed=pkoUNMIS)  , cluster(idhh)

drop agri_w* pasture_w*




/*------------------------------------------------------------------------------

	SECTION D. Robustness checks 

------------------------------------------------------------------------------*/

* 1.Excluding country capital Juba
foreach outcome of global outcome {
	reghdfe `outcome' pkoarmed  $micro $macro if cty!=2301, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
	}

* 2.Removing households from wave 3
foreach outcome of global outcome {
	reghdfe `outcome' pkoarmed  $micro $macro if wave_number!=3, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
	}

* 3.Accounting for possible spatial interdependencies
reghdfe pcqcons Wpcqcons pkoarmed  $micro $macro, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
reghdfe hunger Whunger pkoarmed  $micro $macro, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
reghdfe pcqpurc Wpcqpurc pkoarmed  $micro $macro, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
reghdfe pcwealthdg Wpcwealthdg pkoarmed  $micro $macro, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)

* 4.Including ACLED conflict data as control variable
foreach outcome of global outcome {
	reghdfe `outcome' pkoarmed  $micro $macro acled_count, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
	}

* 5.Including UNMIS deployment interacted with waves as control variable
foreach outcome of global outcome {
	reghdfe `outcome' pkoarmed  $micro $macro pkoUNMIS#i.wave_n, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
	}

* 6.Using logistic regression and poisson regression rather than OLS

poisson pcqcons  pkoarmed i.cty i.wave_n $micro $macro,  vce(cluster idhh)
margins, dydx(pkoarmed)

logit hunger pkoarmed i.cty i.wave_n $micro $macro,  vce(cluster idhh)
margins, dydx(pkoarmed) 

poisson pcqpurc  pkoarmed i.cty i.wave_n $micro $macro,  vce(cluster idhh)
margins, dydx(pkoarmed)

poisson pcwealthdg  pkoarmed i.cty i.wave_n $micro $macro ,  vce(cluster idhh)
margins, dydx(pkoarmed)

* 7.Using the logged number of peacekeepers deployed
foreach outcome of global outcome {
	reghdfe `outcome' lntroop  $micro $macro, /*
	*/ absorb(cty wave_number) vce(cluster i.idhh)
	}
